﻿using System;
using System.Collections.Generic;
using System.Reflection;

namespace Fabrication.ValueProviders
{
    internal sealed class DictionaryProvider : IValueProvider
    {
        private static readonly Type dictionaryType = typeof(Dictionary<,>);
        private Type specificDictionaryType;

        public void Initialize(PropertyInfo property)
        {
            var itemTypes = property.PropertyType.GetGenericArguments();
            specificDictionaryType = dictionaryType.MakeGenericType(itemTypes);
        }

        object IValueProvider.GetValue(object item)
        {
            return Activator.CreateInstance(specificDictionaryType);
        }
    }
}